package com.compass.mobile.presenters

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.leanback.widget.Presenter
import com.compass.mobile.R
import com.compass.mobile.framework.ext.gone
import com.compass.mobile.framework.ext.visible
import com.compass.mobile.framework.utils.DateUtils
import com.compass.mobile.models.InspectionReport

/**
 * Description： 检查
 * Date:2024/6/29 15:29
 */
class MyTestReportPresenter : Presenter() {

    override fun onCreateViewHolder(viewGroup: ViewGroup): ViewHolder {
        val view = LayoutInflater.from(viewGroup.context)
            .inflate(R.layout.item_test_report, viewGroup, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(viewHolder: Presenter.ViewHolder, item: Any) {
        if (item is InspectionReport) {
            val vh = viewHolder as ViewHolder
            vh.tvReportName.text = item.reportName
            vh.tvCheckTime.text =
                "检查时间: ${DateUtils.conversionTime(item.checkTime, DateUtils.FORMAT_TWO)}"
            vh.tvReportNumber.text = "报告单号: ${item?.reportNumber}"
            if (isShowCloudFilm(item?.reportName)) vh.tvFilm.visible() else vh.tvFilm.gone()


        }
    }

    private fun isShowCloudFilm(reportName: String?): Boolean {
        reportName?.let {
            return (it.contains("数字化摄影（DR）") || it.contains("CT") || it.contains(
                "1.5T MR"
            )
                    || it.contains("3.0T MR") || it.contains("数字胃肠") || it.contains(
                "乳腺X线摄影"
            ))
        } ?: kotlin.run {
            return false
        }

    }

    override fun onUnbindViewHolder(viewHolder: Presenter.ViewHolder) {

    }


    class ViewHolder(view: View) : Presenter.ViewHolder(view) {
        var tvReportName: TextView
        var tvCheckTime: TextView
        var tvReportNumber: TextView
        var tvFilm: TextView


        init {
            tvReportName = view.findViewById(R.id.tvReportName)
            tvCheckTime = view.findViewById(R.id.tvCheckTime)
            tvReportNumber = view.findViewById(R.id.tvReportNumber)
            tvFilm = view.findViewById(R.id.tvFilm)


        }
    }

    private fun sexString(patientSex: String?): String {
        patientSex?.let {
            return if (it == "F") {
                "女"
            } else {
                "男"
            }
        } ?: kotlin.run {
            return "未知"
        }

    }
}